- can use different edge-specific plotting parameters (color,linetype) to indicate the type
- simplify the network by types.
- can use different facet to present different networks with fixing layout (using
ggnetwork will be more convenient)
data(enron)
subenron=induced_subgraph(enron,V(enron)[1:30])
subenron
## IGRAPH d238df7 D--- 30 2133 -- Enron email network
## + attr: LDC_names (g/c), LDC_desc (g/c), name (g/c), Citation
## | (g/c), Email (v/c), Name (v/c), Note (v/c), Time (e/c),
## | Reciptype (e/c), Topic (e/n), LDC_topic (e/n)
## + edges from d238df7:
## [1] 1->10 1->10 1->10 1->10 1->10 1->10 1->10 1->10 1->10 1->10 1->10
## [12] 1->10 1->10 1->10 1->10 1->10 1->10 1->10 1->10 1->10 1->10 1->10
## [23] 1->10 1->21 1->21 1->21 1->21 2-> 2 2->16 2->16 2->16 2->16 2->16
## [34] 2->16 2->16 3->11 3->11 3->11 3->11 3->18 3->18 3->18 3->18 5-> 2
## [45] 5-> 2 5-> 2 5-> 2 5-> 2 5-> 2 5-> 5 5-> 5 5-> 5 5-> 5 5-> 5 5-> 5
## [56] 5-> 5 5-> 5 5-> 5 5-> 6 5-> 6 5-> 6 5-> 6 5-> 6 5-> 6 5-> 7 5-> 7
## + ... omitted several edges
E(subenron)$Reciptype%>%unique()
## [1] "to" "bcc" "cc"
E(subenron)$color <- c("gold", "tomato", "yellowgreen")[E(subenron)$Reciptype%>%as.factor()]
set.seed(1)
plot(subenron,edge.arrow.size=0.2,layout=layout_in_circle,vertex.label=NA,vertex.size=2)

#merge the edges by type
subenron.df=igraph::as_data_frame(subenron)
se.df=subenron.df%>%group_by(from,to,Reciptype)%>%summarise(weight=n())
se.net=graph_from_data_frame(se.df)
E(se.net)$color <- c("gold", "tomato", "yellowgreen")[E(se.net)$Reciptype%>%as.factor()]
set.seed(1)
plot(se.net,edge.arrow.size=0.2,layout=layout_in_circle,vertex.label=NA,vertex.size=2)

#edge.width=log(E(se.net)$weight+0.1)/4 #can set the width of edge
To delete edges, using - or delete_edges(graph,edges)
To keep the subgraph with specific edges, using subgraph.edges(graph, eids, delete.vertices = FALSE)
set.seed(1)
#fix the layout
l=layout_in_circle(se.net)
plot(se.net,edge.arrow.size=0.2,layout=l,vertex.shape="none")

#delete the edges
se.net.to=se.net-E(se.net)[E(se.net)$Reciptype%in%c("cc","bcc")]
#se.net.to=delete.edges(se.net,E(se.net)[E(se.net)$Reciptype%in%c("cc","bcc")]) #another way to delete
#se.net.to=subgraph.edges(se.net,E(se.net)[E(se.net)$Reciptype=="to"],delete.vertices = FALSE) # keep the subgraph
se.net.cc=se.net-E(se.net)[E(se.net)$Reciptype%in%c("to","bcc")]
se.net.bcc=se.net-E(se.net)[E(se.net)$Reciptype%in%c("to","cc")]
par(mfrow=c(1,3))
plot(se.net.to,edge.arrow.size=0.2,layout=l,vertex.shape="none")
plot(se.net.cc,edge.arrow.size=0.2,layout=l,vertex.shape="none")
plot(se.net.bcc,edge.arrow.size=0.2,layout=l,vertex.shape="none")
